package com.wry.wry_test.utils;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.parser.OpenAPIV3Parser;

public class Main {
    public static void main(String[] args) throws Exception {
        String path2 = "E:\\工作文档\\data\\sample.yaml";
        String path3 = "E:\\工作文档\\data\\sample.json";
        String path4 = "E:\\工作文档\\data\\接口文档.openapi.yaml";
        String path5 = "E:\\工作文档\\data\\iserver.openapi.yaml";
        String path6 = "E:\\工作文档\\data\\iserver.openapi.json";
        String path7 = "E:\\工作文档\\data\\iserver-openapi-public-all.json";
        String path8 = "E:\\工作文档\\data\\iserver-openapi-public-simple.yaml";


        String json = JsonVerify.yamlToJson(path7);
        json = JSONUtil.jsonWashing(json, "example");
        System.out.println(json);
        ObjectMapper objectMapper = new ObjectMapper();

//        OpenAPI openApi = objectMapper.readValue(json.getBytes(StandardCharsets.UTF_8), OpenAPI.class);


        OpenAPIV3Parser parser = new OpenAPIV3Parser();
        ObjectMapper yamlMapper = new ObjectMapper(new YAMLFactory());
        // 将JSON字符串转换为Java对象
        Object obj = objectMapper.readValue(json, Object.class);
        // 将Java对象转换为YAML字符串
        String yamlOutput = yamlMapper.writeValueAsString(obj);

        OpenAPI openApi = parser.readContents(yamlOutput).getOpenAPI();

        // 打印解析后的OpenAPI对象信息，根据需要处理这个对象
        System.out.println(openApi);

    }
}
